package com.cn.indentManage.serviceImpl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import com.cn.indentManage.dao.IndentDao;
import com.cn.indentManage.entity.Page;
import com.cn.indentManage.service.IndentService;
@Service("indentService")
@Transactional(rollbackFor=Exception.class)
public class IndentServiceImpl implements IndentService {
	@Resource
	private IndentDao indentDao;
	
	/*
	 * 查询订单
	 */
	public Page selectAllIndents(Model model, int currentPage){
		Page<Map<String, Object>> page=new Page<Map<String, Object>>();
		page.setRows(indentDao.IndentCount());
		page.setCurrentPage(currentPage);
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("page", page.getBegin());
		map.put("pageSize",page.getPageSize());
		List<Map<String, Object>> list = indentDao.selectAllIndents(map);
		model.addAttribute("status", 9);
		page.setList(list);
		return page;
	}

	/**
	 * 修改订单状态
	 */
	public void upIndentByindentId(int indentId,int status) {
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("indentId", indentId);
		map.put("status",status);
		indentDao.upIndentByindentId(map);
	}
	/*
	 * 订单详情
	 */
	public List<Map<String, Object>> selectIndentXq(int indentId,Model model){
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("indentId",indentId);
		List<Map<String, Object>> list = indentDao.selectIndentXq(map);
		for(Map<String, Object>m:list){
			Map<String, Object>map1 =new HashMap<String, Object>();
			map1.put("goodsId", m.get("goodsId"));
			List<Map<String, Object>> s = indentDao.selectpeijianXq(map1);
			m.put("chicun", s);
			Map<String,Object> m1=new HashMap<String,Object>();
			m1.put("goodsId", m.get("goodsId"));
			m.put("sum",indentDao.findPjSum(map1));
		}
		return list;
	}
	/*
	 * 配件详情
	 */
	public List<Map<String, Object>> selectpeijianXq(int goodsId) {
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("goodsId",goodsId);
		List<Map<String, Object>>list=indentDao.selectpeijianXq(map);
		return list;
	}
	
	/*
	 * 单个配件详情
	 */
	public List<Map<String, Object>> selectpeijianXq2(int goodsId) {
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("specialId",goodsId);
		List<Map<String, Object>>list=indentDao.selectpeijianXq2(map);
		return list;
	}
	
	
	
	/*
	 * 通过订单号查询订单
	 */
	public List<Map<String, Object>> selectIndent(Model model, int indentId) {
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("indentId",indentId);
		List<Map<String, Object>> list = indentDao.selectIndent(map);
		return list;
	}
	/*
	 * 通过订单状态筛选订单
	 * 
	 */
	
	public Page selectAllIndentbystatus(Model model, int currentPage, Integer status) {
		Page<Map<String, Object>> page=new Page<Map<String, Object>>();
		page.setRows(indentDao.IndentCountbystatus(status));
		page.setCurrentPage(currentPage);
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("page", page.getBegin());
		map.put("pageSize",page.getPageSize());
		map.put("status",status);
		List<Map<String, Object>> list = indentDao.selectAllIndentbystatus(map);
		page.setList(list);
		return page;
		
	}

	

}
